use serde::Serialize;

#[derive(Serialize)]
pub struct User {
    pub name: String,
    pub age: u8, // 只使用u8就够了...sign
    pub email: String,
}

pub fn try_struct1() -> (User, User) {
    let user1 = User {
        name: String::from("Alice"),
        age: 30,
        email: String::from("alice@sohu.com"),
    };
    let user2 = User {
        name: String::from("Bob"),
        email: String::from("bob@hotmail.com"),
        ..user1
    };
    (user1, user2)
}

#[derive(Serialize)]
pub struct Color(u8, u8, u8);

pub fn try_struct2() -> (Color, u8, u8, u8) {
    let black = Color(0, 0, 0);
    let white = Color(255, 255, 255);
    let Color(r, g, b) = white;
    // let white: Color = Color(255, 255, 255);
    // println!("black: {}, {}, {}", black.0, black.1, black.2);
    // println!("white: {}, {}, {}", white.0, white.1, white.2);
    (black, r, g, b)
}

pub struct Rectangle {
    pub width: u32,
    pub height: u32,
}

impl Rectangle {
    pub fn area(&self) -> u32 {
        self.width * self.height
    }
}

pub mod option {
    pub fn plus_one(x: Option<i32>) -> Option<i32> {
        match x {
            None => None,
            Some(i) => Some(i + 1),
        }
    }
}
